import 'package:dio/dio.dart';

class RequestConfig {
  final String path;
  final String method;
  Map<String, dynamic>? queryParameters;
  Map<String, dynamic>? data;
  final CancelToken? cancelToken;
  final Options? options;
  final ProgressCallback? onSendProgress;
  final ProgressCallback? onReceiveProgress;
  final bool showLog;

  factory RequestConfig.empty() {
    return RequestConfig(path: '', method: 'get');
  }

  RequestConfig({
    required this.path,
    required this.method,
    this.queryParameters,
    this.data,
    this.options,
    this.cancelToken,
    this.onSendProgress,
    this.onReceiveProgress,
    this.showLog = false,
  });

  factory RequestConfig.fromGet(
    final String path, {
    final Map<String, dynamic>? queryParameters,
    final CancelToken? cancelToken,
    final Options? options,
    final ProgressCallback? onSendProgress,
    final ProgressCallback? onReceiveProgress,
    final bool showLog = false,
  }) {
    return RequestConfig(
      path: path,
      method: 'GET',
      options: options,
      queryParameters: queryParameters,
      onSendProgress: onSendProgress,
      onReceiveProgress: onReceiveProgress,
      showLog: showLog,
    );
  }

  factory RequestConfig.fromPost(
    final String path, {
    final Map<String, dynamic>? data,
    final CancelToken? cancelToken,
    final Options? options,
    final ProgressCallback? onSendProgress,
    final ProgressCallback? onReceiveProgress,
    final bool showLog = false,
  }) {
    return RequestConfig(
      path: path,
      method: 'POST',
      data: data,
      options: options,
      cancelToken: cancelToken,
      onSendProgress: onSendProgress,
      onReceiveProgress: onReceiveProgress,
      showLog: showLog,
    );
  }

  RequestConfig copyWithQueryParameters(
      final Map<String, dynamic> queryParameters) {
    return RequestConfig(
        path: path, method: method, queryParameters: queryParameters);
  }

  RequestConfig copyWithData(final Map<String, dynamic> data) {
    return RequestConfig(path: path, method: method, data: data);
  }
}
